/**
 * 
 */
package de.tum.in.eist.poll.client.views.widgets;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Label;

import de.tum.in.eist.poll.client.controllers.Controller;
import de.tum.in.eist.poll.client.views.Views;

/**
 * A Widget for the menubar in the title bar, such as navigation links
 * 
 * @author Sebastian Hofstetter
 * 
 */
public class MenuWidget extends HorizontalPanel {
	Label pollLabel = new Label("Poll");
	Label evaluationLabel = new Label("Evaluation");
	Label userManagementLabel = new Label("User Management");
	Label lectureManagementLabel = new Label("Add Lecture");

	/**
	 * assosciates the links with the correct pages and shows only links to
	 * accessable pages
	 */
	public MenuWidget() {
		// poll
		if (Controller.controller.canSee(Views.poll)) {
			pollLabel.addClickHandler(new ClickHandler() {
				@Override
				public void onClick(ClickEvent event) {
					Controller.controller.showPage(Views.poll);
				}
			});
			pollLabel.addStyleName("menuItem");
			if (Controller.controller.canSee(Views.poll))
				add(pollLabel);
		}

		// evaluation
		if (Controller.controller.canSee(Views.evaluation)) {
			evaluationLabel.addClickHandler(new ClickHandler() {
				@Override
				public void onClick(ClickEvent event) {
					Controller.controller.showPage(Views.evaluation);
				}
			});
			evaluationLabel.setStyleName("menuItem");
			if (Controller.controller.canSee(Views.evaluation))
				add(evaluationLabel);
		}

		// userManagement
		if (Controller.controller.canSee(Views.userManagement)) {
			userManagementLabel.addClickHandler(new ClickHandler() {
				@Override
				public void onClick(ClickEvent event) {
					Controller.controller.showPage(Views.userManagement);
				}
			});
			userManagementLabel.addStyleName("menuItem");
			if (Controller.controller.canSee(Views.userManagement))
				add(userManagementLabel);
		}

		// lectureManagement
		if (Controller.controller.canSee(Views.lectureManagement)) {
			lectureManagementLabel.addClickHandler(new ClickHandler() {
				@Override
				public void onClick(ClickEvent event) {
					Controller.controller.showPage(Views.lectureManagement);
				}
			});
			lectureManagementLabel.addStyleName("menuItem");
			if (Controller.controller.canSee(Views.lectureManagement))
				add(lectureManagementLabel);
		}

		setStyleName("menu");
	}
}
